package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.CollectBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class NewsCollectPresenter extends basePresenter {

    private Contract.NewsCollectView newsCollectView;

    public NewsCollectPresenter(Contract.NewsCollectView view) {
        super(view);
        this.newsCollectView = view;
    }

    public void initData(int page, final boolean isRefresh, boolean isShowDialog) {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.COLLECT_LIST);
        rp.addBodyParameter("longitude", MyApplication.location.getLongitude()+"");
        rp.addBodyParameter("latitude", MyApplication.location.getLatitude()+"");
        rp.addBodyParameter("type","2");
        rp.addBodyParameter("page",page+"");
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, CollectBean.class,isShowDialog, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                CollectBean bean = (CollectBean) baseBean;
                if (isRefresh) {
                    newsCollectView.onRefresh(bean);
                }else {
                    newsCollectView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                newsCollectView.onFail();
            }
        });
    }

}
